<?php

$configQuene = array('host' => 'localhost', 'port' => '5672', 'login' => 'guest', 'password' => 'guest');
$conn = new AMQPConnection($configQuene);
$m = $conn->connect();
if (!$m){
	die("Cannot connect to the broker \n ");
}
while (true) {
	$config = [
		'eqeueName' => 'storage',
	];
	$q_name = $config['eqeueName'];
	$channel = new AMQPChannel($conn);
	$q = new AMQPQueue($channel);
	$q->setName($q_name);
	$arr = $q->get();
	if (!$arr)
		die("Not Any Storage");
	$ack = $arr->getDeliveryTag();
	$res = $q->ack($ack);
	$msg = $arr->getBody();
	echo $msg . "\n";

	$userRequest = new AMQPQueue($channel);
	$userRequest->setName("userRequest");
	$m = $userRequest->get();
	if (!$m)
		die("Not Any Request!");
	$req = $m->getBody();
	$tag = $m->getDeliveryTag();

//	todo :insert into table
	$userRequest->ack($tag);
	echo $req . "\n";

	sleep(1);
}
